package com.nowcoder;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 *输入两手牌，两手牌之间用"-"连接，每手牌的每张牌以空格分隔，"-"两边没有空格，如：4 4 4 4-joker JOKER。
 *请比较两手牌大小，输出较大的牌，如果不存在比较关系则输出ERROR。
 */
public class PokerCompare {
    private String cardStr;
    private String []cards;
    public PokerCompare(String cardStr) {
        this.cards = cardStr.split(" ");
        this.cardStr = cardStr;
    }
    private Map<String, Integer> map = new HashMap(){
        {
            put("3", 3);
            put("4", 4);
            put("5", 5);
            put("6", 6);
            put("7", 7);
            put("8", 8);
            put("9", 9);
            put("10", 10);
            put("J", 11);
            put("Q", 12);
            put("K", 13);
            put("A", 14);
            put("2", 15);
            put("joker", 16);
            put("JOKER", 17);
        }
    };
    private int getCardNumber(String card) {
        return map.get(card);
    }
    private boolean isBoom() {
        if (cards == null || cards.length < 4) {
            return false;
        }
        for (String s : cards) {
            if (!s.equals(cards[0])) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        String[] ss = line.split("-");
        PokerCompare p0 = new PokerCompare(ss[0]);
        PokerCompare p1 = new PokerCompare(ss[1]);
        int cardNumber0 = p0.getCardNumber(p0.cards[0]);
        int cardNumber1 = p1.getCardNumber(p1.cards[0]);
        if ("JOKER joker".equals(ss[0]) || "joker JOKER".equals(ss[0])) {
            System.out.println(ss[0]);
        } else if ("JOKER joker".equals(ss[1]) || "joker JOKER".equals(ss[1])) {
            System.out.println(ss[1]);
        } else if (p0.isBoom() && p1.isBoom()) {
            System.out.println(cardNumber0 > cardNumber1 ? p0.cardStr : p1.cardStr);
        } else if (p0.isBoom()) {
            System.out.println(p0.cardStr);
        } else if (p1.isBoom()) {
            System.out.println(p1.cardStr);
        } else if (p0.cards.length == p1.cards.length) {
            System.out.println(cardNumber0 > cardNumber1 ? p0.cardStr : p1.cardStr);
        } else {
            System.out.println("ERROR");
        }
    }
}
